package com.effectiv.gooruda.rest.service.impl;

import jodd.util.StringUtil;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.social.twitter.api.Twitter;
import org.springframework.social.twitter.api.impl.TwitterTemplate;
import org.springframework.stereotype.Component;

import com.effectiv.gooruda.domain.SocialProvider;
import com.effectiv.gooruda.repository.SocialProviderRepository;

@Component
public class SocialResolver {

	@Autowired
	private SocialProviderRepository repository;

	public Twitter resolveTwitter(String providerKey) {
		SocialProvider provider = repository.findByProviderKey(providerKey);
		Twitter twitter = null;

		if (provider != null) {

			if (StringUtil.equals(provider.getType(), "TWITTER")) {
				twitter = new TwitterTemplate(provider.getKey1(), provider.getKey2(),
						provider.getKey3(), provider.getKey4());
			}
		}
		
		return twitter;
	}
}
